package com.myexploit.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.myexploit.pojo.Item;
import com.myexploit.vo.EasyUITable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.myexploit.mapper.ItemMapper;

import java.util.List;

@Service
public class ItemServiceImpl implements ItemService {//eclipse alt + shift + p

	@Autowired
	private ItemMapper itemMapper;

	/**
	 *
	 */
	@Override
	public EasyUITable findItemByPage(Integer page, Integer rows) {
//		//1.计算起始位置
//		int startIndex = (page-1)*rows;
//		List<Item> itemList = itemMapper.findItemByPage(startIndex,rows);
//        //2.获取总记录数
//		int total = itemMapper.selectCount(null);

		QueryWrapper<Item> queryWrapper = new QueryWrapper<>();
		queryWrapper.orderByDesc("updated");
		IPage<Item> iPage = new Page<>(page,rows);
		iPage = itemMapper.selectPage(iPage,queryWrapper);
		int total = (int)iPage.getTotal();
		List<Item> itemList = iPage.getRecords();
		return new EasyUITable(total,itemList);
	}
}
